
//
//  BGBrandZoneViewController.m
//  bigMall
//
//  Created by 大魔王 on 2016/12/29.
//  Copyright © 2016年 thinklev. All rights reserved.
//

#import "BGBrandZoneViewController.h"
#import "BGDateResult.h"
#import "BGCollectionViewCell.h"
#import "BGBrandZoneModel.h"
#import "UIImageView+WebCache.h"
#import "BGBasicUrl.h"

@interface BGBrandZoneViewController ()<UICollectionViewDataSource,UICollectionViewDelegateFlowLayout,UICollectionViewDelegateFlowLayout> {
    NSMutableArray *dataArr;
}
@property (nonatomic,strong) UICollectionView *collectionView;
@end

@implementation BGBrandZoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    dataArr = [NSMutableArray array];
    self.title = @"品牌专区";
    [self.view addSubview:self.collectionView];
    [self loadInter];
    
}
- (void)loadInter {
    
    [BGDateResult brandListWithThisPage:@"1" pageNum:@"19" success:^(NSObject *result) {
       
        BGBrandZoneModel *model  = (BGBrandZoneModel *)result;
        for (int i = 0;i < model.res.count;i++) {
            BGBrandZoneModelTwo *modelTw = model.res[i];
            [dataArr addObject:modelTw.brand_image_path];
        }
        
        [self.collectionView reloadData];
        
    } failure:^(NSError *error) {
        
    }];
    
}
- (UICollectionView *)collectionView {
    
    if (_collectionView == nil) {
        
        UICollectionViewFlowLayout *flowLauout = [[UICollectionViewFlowLayout alloc] init];
        flowLauout.headerReferenceSize = CGSizeMake(0, 0);
        flowLauout.scrollDirection = UICollectionViewScrollDirectionVertical;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, BGWidth, BGHight) collectionViewLayout:flowLauout];
        flowLauout.itemSize = CGSizeMake(BGWidth - 100, (BGWidth - 100) / 7);
        flowLauout.minimumLineSpacing = 5;
        flowLauout.minimumInteritemSpacing = 10;
        flowLauout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
        _collectionView.backgroundColor = [UIColor whiteColor];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollsToTop = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        [_collectionView registerNib:[UINib nibWithNibName:@"BGCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:identfy];
        
    }
    return _collectionView;
}
#pragma mark - delegate -
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return dataArr.count;
}
static NSString *identfy = @"celId";
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
//    BGBrandZoneModelTwo *model = dataArr[indexPath.row];
    BGCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identfy forIndexPath:indexPath];
    cell.backgroundColor = [UIColor greenColor];
    cell.selected = NO;
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[BGBasicUrl getBasicUrl],dataArr[indexPath.row]]]];
//    NSLog(@"model.keyValues %@",model.keyValues);
//    NSLog(@"%@",model.brand_image_path);
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
